package com.iwuke.dance.career;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.career.fragment.ActivityFragment;
import com.iwuke.dance.career.fragment.AllFragment;
import com.iwuke.dance.career.fragment.EventFragment;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;

import java.util.Map;

import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/10/16
 * 生涯列表
 */
public class CareerListActivity extends BaseActivity implements View.OnClickListener {



    private RadioGroup radio_group;
    private FrameLayout frame_layout;
    private RadioButton radio_button_1;
    private View v_bottom_1;
    private RadioButton radio_button_2;
    private View v_bottom_2;
    private RadioButton radio_button_3;
    private View v_bottom_3;
    private AllFragment allFragment;
    private ActivityFragment activityFragment;
    private EventFragment eventFragment;
    private ImageView img_left;
    private TextView tv_title_bar;
    private TextView tv_right_search;
    private TextView tv_right_filter;

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent) {
        BaseActivity.setConnect(CareerListActivity.this, networkEvent, null);

    }
    @Override
    protected int getView() {
        return R.layout.activity_career_list;
    }

    @Override
    protected void init(View mView) {

        //返回
        img_left = findViewById(R.id.img_left);
        //标题
        tv_title_bar = findViewById(R.id.tv_title_bar);
        //右边的搜索按钮
        tv_right_search = findViewById(R.id.tv_right_search);
        //右边的筛选按钮
        tv_right_filter = findViewById(R.id.tv_right_filter);

        //切换点击事件
        radio_group = findViewById(R.id.radio_group);
        frame_layout = findViewById(R.id.frame_layout);

        //按钮
        radio_button_1 = findViewById(R.id.radio_button_1);
        v_bottom_1 = findViewById(R.id.v_bottom_1);
        radio_button_1.setText("全部\n(0)");
        //按钮
        radio_button_2 = findViewById(R.id.radio_button_2);
        v_bottom_2 = findViewById(R.id.v_bottom_2);
        radio_button_2.setText("赛事/演出/活动\n(0)");
        //按钮
        radio_button_3 = findViewById(R.id.radio_button_3);
        v_bottom_3 = findViewById(R.id.v_bottom_3);
        radio_button_3.setText("证书\n(0)");


        //标题
        tv_title_bar.setText("生涯列表");
        //返回
        img_left.setOnClickListener(this);
        //右边的搜索按钮
        tv_right_search.setOnClickListener(this);
        //右边的筛选按钮
        tv_right_filter.setOnClickListener(this);

    }

    @Override
    protected void initData() {
        //全部
        initAll();

        //赛事/演出/活动
        initActivity();

        //证书
        initEvent();


        setRadioButtonColor(1);
        switchFragment(allFragment);

        radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.radio_button_1) {
                    //全部
                    setRadioButtonColor(1);
                    switchFragment(allFragment);
                } else if (checkedId == R.id.radio_button_2) {
                    //赛事/演出/活动
                    setRadioButtonColor(2);
                    switchFragment(activityFragment);
                } else if (checkedId == R.id.radio_button_3) {
                    //证书
                    setRadioButtonColor(3);
                    switchFragment(eventFragment);

                }

            }
        });

    }

    public void setRadioButtonColor(int rbn) {
        switch (rbn){
            case 1:
                radioButtonColorUtil(R.color.color_333,R.color.color_666,R.color.color_666);
                v_bottom_1.setVisibility(View.VISIBLE);
                v_bottom_2.setVisibility(View.INVISIBLE);
                v_bottom_3.setVisibility(View.INVISIBLE);
                break;

            case 2:
                radioButtonColorUtil(R.color.color_666,R.color.color_333,R.color.color_666);
                v_bottom_1.setVisibility(View.INVISIBLE);
                v_bottom_2.setVisibility(View.VISIBLE);
                v_bottom_3.setVisibility(View.INVISIBLE);
                break;

            case 3:
                radioButtonColorUtil(R.color.color_666,R.color.color_666,R.color.color_333);
                v_bottom_1.setVisibility(View.INVISIBLE);
                v_bottom_2.setVisibility(View.INVISIBLE);
                v_bottom_3.setVisibility(View.VISIBLE);
                break;

        }
    }

    private void radioButtonColorUtil(int color1,int color2,int color3){
        radio_button_1.setTextColor(getResources().getColor(color1,null));
        radio_button_2.setTextColor(getResources().getColor(color2,null));
        radio_button_3.setTextColor(getResources().getColor(color3,null));
    }

    private void initAll() {
        if (allFragment == null) {
            allFragment = new AllFragment();
            allFragment.setRadioButton(radio_button_1);
            fragmentList.add(allFragment);
        }
    }

    private void initActivity() {
        if (activityFragment == null) {
            activityFragment = new ActivityFragment();
            activityFragment.setRadioButton(radio_button_2);
            fragmentList.add(activityFragment);
        }
    }

    private void initEvent() {
        if (eventFragment == null) {
            eventFragment = new EventFragment();
            eventFragment.setRadioButton(radio_button_3);
            fragmentList.add(eventFragment);
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){//返回
            finish();
        }else if (v.getId()==R.id.tv_right_search){//右边的搜索按钮
            Util.setIntent(CareerListActivity.this,CareerSearchActivity.class);
        }else if (v.getId()==R.id.tv_right_filter){//右边的筛选按钮
            Util.datePicker(CareerListActivity.this);

            Util.setOnStartAndEnd(new Util.OnStartAndEnd() {
                @Override
                public void onStartAndEnd(Map<String, String> map) {
                    //开始时间
//                    tv_start_time.setText(map.get("start"));
                    //结束时间
//                    tv_end_time.setText(map.get("end"));
//                    pageNum=1;
//                    initRequest();
                }
            });
        }
    }
}
